classdef quantization_utils
    methods(Static)
        function q = quantize(x, scale, zero_point)
            % 将浮点数量化为int8
            q = int8(min(max(round(x / scale) + zero_point, -128), 127));
        end
        
        function x = dequantize(q, scale, zero_point)
            % 将int8反量化为浮点数
            x = single((double(q) - double(zero_point)) * scale);
        end
    end
end 